package com.mzj.saas.mservice.property.controller;

import com.mzj.saas.commons.ApiData;
import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.property.service.EstateRepairsCostService;
import com.mzj.saas.mservice.property.vo.EstateRepairsCostV2VO;
import com.mzj.saas.mservice.property.vo.EstateRepairsCostVO;
import com.mzj.saas.mservice.property.vo.RepairsCostListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 收费项目管理
 *
 * @author hikari
 * @since 2021-05-20
 */
@RestController
@RequestMapping("/property/estateRepairsCost")
public class EstateRepairsCostController {
    @Autowired
    private EstateRepairsCostService estateRepairsCostService;

    /**
     * 收费项目列表-app
     *
     * @param accessToken
     * @param type
     * @param repairItem
     * @param model
     * @param communityId
     * @param creator
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @GetMapping
    public ResultBean<ApiData<EstateRepairsCostV2VO>> list(@RequestHeader String accessToken,
                                                           @RequestParam(required = false) Integer type,
                                                           @RequestParam(required = false) String repairItem,
                                                           @RequestParam(required = false) String model,
                                                           @RequestParam(required = false) String communityId,
                                                           @RequestParam(required = false) String creator,
                                                           @RequestParam(defaultValue = "0") Integer pageNumber,
                                                           @RequestParam(defaultValue = "5") Integer pageSize) {
        return estateRepairsCostService.list(accessToken, type, repairItem, model, communityId, creator, pageNumber,
                pageSize);
    }

    /**
     * 收费项目列表-企业端
     * @param accessToken
     * @param type 项目类型
     * @param repairItem 维修项目
     * @param model 规格
     * @param communityId 小区id
     * @param creator 创建人
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @GetMapping("/repairsCostList")
    public ResultBean<ApiData<RepairsCostListVO>> repairsCostList(@RequestHeader String accessToken,
                                                                  @RequestParam(required = false) Integer type,
                                                                  @RequestParam(required = false) String repairItem,
                                                                  @RequestParam(required = false) String model,
                                                                  @RequestParam(required = false) String communityId,
                                                                  @RequestParam(required = false) String creator,
                                                                  @RequestParam(defaultValue = "0") Integer pageNumber,
                                                                  @RequestParam(defaultValue = "5") Integer pageSize) {
        return estateRepairsCostService.repairsCostList(accessToken, type, repairItem, model, communityId, creator, pageNumber,
                pageSize);
    }

    /**
     * 查小区收费项目
     *
     * @param accessToken
     * @param communityId
     * @return
     */
    @GetMapping("/community/{communityId}")
    public ResultBean<List<EstateRepairsCostV2VO>> listByCommunityId(@RequestHeader String accessToken,
                                                                     @PathVariable String communityId) {
        return estateRepairsCostService.listByCommunityId(accessToken, communityId);
    }

    /**
     * 新增收费项目
     *
     * @param accessToken
     * @param estateRepairsCostVO
     * @return
     */
    @PostMapping
    public ResultBean<EstateRepairsCostVO> save(@RequestHeader String accessToken,
                                                @Valid @RequestBody EstateRepairsCostVO estateRepairsCostVO) {
        return estateRepairsCostService.save(accessToken, estateRepairsCostVO);
    }

    /**
     * 删除收费项目
     *
     * @param accessToken
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResultBean<Object> delete(@RequestHeader String accessToken, @PathVariable Long id) {
        return estateRepairsCostService.delete(accessToken, id);
    }


}
